#include<iostream>
#include<fstream>
#include<string.h>
using namespace std;
bool isnum_a(char a)  //判断是否合理
{
	if ((a >= 'A' && a <= 'z'))
		return true;
	else
		return false;
}
void count(fstream& outfile, int* x)
{
	char a[256];
	while (outfile.getline(a, 256))
	{
		int tmp = 0;
		x[5]++;
		for (int i = 0; i < strlen(a); i++)
		{
			if (isnum_a(a[i]))//统计字符数
			{
				x[0]++;   tmp++;
			}
			else if (a[i] == ' ' || a[i] == '.' || a[i] == ',' || a[i] == '?' || a[i] == '!')//统计单词数
				x[1]++;
			else if (a[i] == '.' || a[i] == '?' || a[i] == '!')
				x[2]++;  //统计句子数  
			else if (a[i] == '/' && a[i + 1] == '/') //统计注释数
				x[3]++;
			else if (tmp == 0)//统计空行数 
				x[4]++;
		}
	}
	outfile.close();
	return;
}
int main()
{
	cout<<"先输入wc.exe，功能，文件："<<endl;
	cout<<"-c为字符数,-w为单词数,-s为句子数，-d为代码数，-q为空行数，-p为注释数"<<endl;
	while (1)
	{
		char filename[256];
		int x[3] = { 0 };
		char mod;
		cout << "wc.exe -";//输入文本的路径选择模式1 
		cin >> mod;
		cin.getline(filename, 256);
		fstream outfile(filename, ios::in);
		count(outfile, x);
		if (mod == 'c')
			cout << "文本中的字符数为: " << x[0] << endl;
		else if (mod == 'w')
			cout << "文本中的单词数为:" << x[1] << endl;
		else if (mod == 's')
			cout << "文本中的句子数为:" << x[2] << endl;
		else if (mod == 'd')
			cout << "文本中的代码数为:" << x[5]-x[3]-x[4] << endl;
		
		else if (mod == 'q')
			cout << "文本中的空行数为:" << x[4] << endl;
		
		else if (mod == 'p')
			cout << "文本中的注释数为:" << x[3] << endl;	
	}
	system("pause");
	return 0;
}